package com.chenxin.wms.controller;

import com.chenxin.common.annotation.Log;
import com.chenxin.common.core.controller.BaseController;
import com.chenxin.common.core.domain.AjaxResult;
import com.chenxin.common.core.page.TableDataInfo;
import com.chenxin.common.enums.BusinessType;
import com.chenxin.common.utils.poi.ExcelUtil;
import com.chenxin.system.domain.vo.WmsLogVo;
import com.chenxin.system.service.IWmsLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 作业日志Controller
 *
 * @author gry
 * @date 2025-04-12
 */
@RestController
@RequestMapping("/wms/log")
public class WmsLogController extends BaseController {
    @Autowired
    private IWmsLogService logService;

    /**
     * 查询作业日志列表
     */
    @PreAuthorize("@ss.hasPermi('wms:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsLogVo log) {
        startPage();
        List<WmsLogVo> list = logService.selectLogList(log);
        return getDataTable(list);
    }

    /**
     * 导出作业日志列表
     */
    @PreAuthorize("@ss.hasPermi('wms:log:export')")
    @Log(title = "作业日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsLogVo log) {
        List<WmsLogVo> list = logService.selectLogList(log);
        ExcelUtil<WmsLogVo> util = new ExcelUtil<>(WmsLogVo.class);
        util.exportExcel(response, list, "作业日志数据");
    }

    /**
     * 获取作业日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:log:query')")
    @GetMapping(value = {"/", "/{logId}"})
    public AjaxResult getInfo(@PathVariable(value = "logId", required = false) Long logId) {
        return success(logService.selectLogByLogId(logId));
    }
}
